<%@page import="itsm.isperp.framework.core.context.ContextHolder"%><%@ page
	language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
  String path = request.getContextPath();
  String basePath = ContextHolder.getWebServerName(request);
%>

<script src="<%=path%>/js/dingtalk.js"></script>
<script>
	var dingding = "dingding";
	$.ajax({
	   url:'<%=path%>/api/dingding/getconfig?url=' + window.location.href,
	   success:function(response)
	   {
	      var _config = response;
	     // alert(_config.agentid);
		//alert("_config"+_config);
		dd.config({
			agentId : _config.agentid,
			corpId : _config.corpId,
			timeStamp : _config.timeStamp,
			nonceStr : _config.nonceStr,
			signature : _config.signature,
			jsApiList : [ 'runtime.info', 'biz.contact.choose', 'device.notification.confirm', 'device.notification.alert', 'device.notification.prompt', 'biz.ding.post', 'biz.util.openLink' ]
		});

		/*if(ddurl=="http://localhost:8080/"){
			setUsername("测试1");
		}*/
		dd.ready(function() {
			dd.biz.navigation.setTitle({
				title : 'IT服务平台',
				onSuccess : function(data) {
				  //alert(data);
				},
				onFail : function(err) {
					log.e(JSON.stringify(err));
				}
			});
			dd.runtime.info({
				onSuccess : function(info) {
					logger.e('runtime info: ' + JSON.stringify(info));
				},
				onFail : function(err) {
					logger.e('fail: ' + JSON.stringify(err));
				}
			});
			dd.ui.pullToRefresh.enable({
				onSuccess : function() {
				},
				onFail : function() {
				}
			})

			dd.runtime.permission.requestAuthCode({
				corpId : _config.corpId,
				onSuccess : function(info) {
					//alert('authcode: ' + info.code);
					window.location.href='<%=path%>/api/wechat/v2/wechat/toPage?code='+info.code+'&corpid='+ _config.corpId;
					<%-- $.ajax({
						url : '<%=path%>/api/dingding/userinfo?code=' + info.code + '&corpid=' + _config.corpId,
						type : 'GET',
						success : function(data, status, xhr) {
							alert(data.jobnumber);
							var info = JSON.parse(data);

							alert(info.jobnumber);
							setUsername(info.jobnumber);

						},
						error : function(xhr, errorType, error) {
							logger.e("yinyien:" + _config.corpId);
							alert(errorType + ', ' + error);
						}
					}); --%>

				},
				onFail : function(err) {
					alert('fail: ' + JSON.stringify(err));
				}
			});
		});

		dd.error(function(err) {
			alert('dd error: ' + JSON.stringify(err));
		});
	   }
	
	});
</script>
<div>登陆中...</div>



